package chapter1.String.task;

/*
4：传闻StringBuilder比StringBuffer快,
比较一下，输出你的比较结果（拼接10万个相同的字符串，比较时间）。
 */
public class Task4 {
    public static void main(String[] args) {
        StringBuilder a = new StringBuilder("");
        StringBuffer b = new StringBuffer("");
        String c = "你好";
        long begin1 = System.currentTimeMillis();
        for (int i = 0; i < 100000; i++)
            a.append(c);
        long end1 = System.currentTimeMillis();
        long time1 = end1 - begin1;
        System.out.println("StringBuilder耗时：" + time1 + "毫秒");
        long begin2 = System.currentTimeMillis();
        for (int i = 0; i < 100000; i++)
            b.append("c");
        long end2 = System.currentTimeMillis();
        long time2 = end2 - begin2;
        System.out.println("StringBuffer耗时：" + time2 + "毫秒");
    }
}
